package logic

import (
	"cloud-disk/core/models"
	"cloud-disk/core/utils"
	"context"

	"cloud-disk/core/internal/svc"
	"cloud-disk/core/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FileShareCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFileShareCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FileShareCreateLogic {
	return &FileShareCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FileShareCreateLogic) FileShareCreate(req *types.FileShareCreateRequest, UserIdentity string) (resp *types.FileShareCreateResponse, err error) {
	data := &models.ShareBasic{
		Identity:           utils.GetUUID(),
		UserIdentity:       UserIdentity,
		RepositoryIdentity: req.RepositoryIdentity,
		ExpiredTime:        req.ExpiredTime,
	}
	err = l.svcCtx.DbConn.Create(data).Error
	if err != nil {
		return
	}
	resp = &types.FileShareCreateResponse{
		Identity: data.Identity,
	}
	return
}
